package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.RoleResourcesService;
import com.yixun.qfbao.apidto.GetAuthorizeRoleListReqDto;
import com.yixun.qfbao.apidto.GetAuthorizeRoleListResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.GetAuthorizeRoleListReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 获取角色授权资源列表
 *
 * @author guifang.weng
 * @create 2017-11-22 17:03
 **/
@Service("GetAuthorizeRoleListForDevelopHander")
public class GetAuthorizeRoleListForDevelopHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetAuthorizeRoleListForDevelopHander.class);

    @Autowired
    private RoleResourcesService roleResourcesService;

    @Autowired
    private LoginUtils loginUtils;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetAuthorizeRoleListResDto> res = new BaseResponseDTO<>();
        GetAuthorizeRoleListReqVo reqVo = (GetAuthorizeRoleListReqVo) reqDto;
        GetAuthorizeRoleListReqDto getAuthorizeRoleListReqDto = reqVo.getParams();
        try {
            getAuthorizeRoleListReqDto.setMerchantId(loginUtils.getUser(getAuthorizeRoleListReqDto.getUserId()).getHigherid());
            GetAuthorizeRoleListResDto resDto = roleResourcesService.getAuthorizeRoleListForDeveloper(getAuthorizeRoleListReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (Exception e) {
            logger.error("GetAuthorizeRoleListForDevelopHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("获取角色授权资源列表失败");
        }
        return res;
    }
}
